< previous page page_417 next page >

Page 417
drop events. Depending on how a given control or application supports it and the type of data being dragged, automatically dragging and dropping data may be the best and simplest method.
When using manual drag and drop, you must code for one or more of the OLE drag-and-drop events. Manual implementation of OLE drag and drop may be the better method when you need greater control over each step in the process or you need to provide the user with customized visual feedback or as you will see, dragging a record key into a complex control to display a row of data from a database. Manual implementation is the only option when a control doesn't support the automatic drag-and-drop features.
The Automatic Process
If the controls you want to use support automatic drag and drop, you can activate the features by setting the control's OLEDragMode or OLEDropMode properties to Automatic. However, automatic support does have its limitations. Some of them are derived from the controls themselves. For example, if you move text from a Word document into a text box, all the rich text formatting in the Word document is stripped out because the standard TextBox control doesn't support this formatting. Similar limitations exist for most controls. The RichTextBox control is the correct control to use for this particular situation.
If you change the text box/WordPad example to a RichTextbox control and Microsoft Word, you would then be able to move formatted text between the two applications.
Understanding the Manual Process
The manual process is more involved, but it gives you complete control over the entire OLE drag-and-drop process. To understand how the manual process works, review the available events, methods and objects and see how they work together.
Starting a manual drag-and-drop operation is as simple as calling the OLEDrag method. You then set the drop effects that you want to support, the supported data formats, and if necessary, you can place data into the DataObject. When the OLEDrag method is executed to start the drag operation, the OLEStartDrag event is triggered to enable you to set the effects and formats.
The DataObject
Because OLE drag and drop is implemented across applications, you would not always know where the data being processed is coming from. The event code must work whether the data is within the same application or from another application such as Word or Excel. Visual Basic provides an object that contains the data being moved, no matter where it comes from. The DataObject object contains the data as it moves from the

 
< previous page page_417 next page >

If you like this book, buy it!